package com.ruoyi.sms.entity;

import com.ruoyi.sms.enums.ResultCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 短信发送响应结果
 */
public class SmsResponse {
    private Boolean success;

    private Integer code;

    private String message;

    private Map<String, String> data = new HashMap<>();

    private SmsResponse() {
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, String> getData() {
        return data;
    }

    public void setData(Map<String, String> data) {
        this.data = data;
    }

    // 提供两个默认方法：成功 or 失败
    public static SmsResponse success(){
        SmsResponse resp = new SmsResponse();
        resp.setSuccess(true);
        resp.setCode(ResultCode.SUCCESS.getCode());
        resp.setMessage(ResultCode.SUCCESS.getStatus());
        return resp;
    }

    public static SmsResponse success(String msg){
        SmsResponse resp = new SmsResponse();
        resp.setSuccess(true);
        resp.setCode(ResultCode.SUCCESS.getCode());
        resp.setMessage(msg);
        return resp;
    }

    public static SmsResponse error(){
        SmsResponse resp = new SmsResponse();
        resp.setSuccess(false);
        resp.setCode(ResultCode.ERROR.getCode());
        resp.setMessage(ResultCode.ERROR.getStatus());
        return resp;
    }

    public static SmsResponse error(String msg){
        SmsResponse resp = new SmsResponse();
        resp.setSuccess(false);
        resp.setCode(ResultCode.ERROR.getCode());
        resp.setMessage(msg);
        return resp;
    }


    // 提供链式操作方法，自定义返回数据
    public SmsResponse success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public SmsResponse message(String message){
        this.setMessage(message);
        return this;
    }

    public SmsResponse code(Integer code){
        this.setCode(code);
        return this;
    }

    public SmsResponse data(String key, String value){
        this.data.put(key,value);
        return this;
    }

    public SmsResponse data(Map<String, String> map){
        this.setData(map);
        return this;
    }

}
